package com.nintendo.bubblechat.controller;

import com.nintendo.bubblechat.entity.dto.UserDTO;
import com.nintendo.bubblechat.entity.vo.UsersVo;
import com.nintendo.bubblechat.grace.result.GraceJsonRequest;
import com.nintendo.bubblechat.service.UsersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
@Slf4j
public class UsersController {
    @Autowired
    private UsersService usersService;
    @PostMapping("/register")
    public GraceJsonRequest register(@RequestParam("phone")String phone){
        UsersVo userVo = usersService.saveUser(phone);
        return GraceJsonRequest.ok(userVo);
    }

    /**
     * 修改用户信息
     * @param userDTO
     * @return
     */
    @PostMapping("/updateUserInfo")
    public GraceJsonRequest updateUserInfo(@RequestBody UserDTO userDTO){
        UsersVo usersVo = usersService.updateUserInfo(userDTO);
        return GraceJsonRequest.ok(usersVo);
    }
    @PostMapping("/findUserById")
    public GraceJsonRequest findUserById(@RequestParam("senderId")String senderId){
        UsersVo usersVo = usersService.findUserById(senderId);
        return GraceJsonRequest.ok(usersVo);
    }
    @PostMapping("/findUserInfoById")
    public GraceJsonRequest findUserInfoById(@RequestParam("friendId")String friendId){
        UsersVo usersVo = usersService.findUserById(friendId);
        return GraceJsonRequest.ok(usersVo);
    }
}
